﻿using Shop.Application.Products.Dto;
using Shop.DB;
using Shop.Domain.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Shop.Application.Products
{
   public class CreateProduct
    {
        private DBContext _context;
        public CreateProduct(DBContext context)
        {
            _context = context;
        }

        public async Task<bool> Do(ProductInput input)
        {
            if (input == null) return false;
            var product = new Product
            {
                ProductID = Guid.NewGuid(),
                Name = input.Name,
                Description = input.Description,
                Value = Decimal.Parse(input.Value)
            };
            await _context.Products.AddAsync(product);
            return await _context.SaveChangesAsync() > 0;
        }
    }
}
